package com;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import com.EffectMgr.*;

// 所有技能效果
public class SkillEffect {
    static void EarthQuake(ArrayList<Object> cfg, Unit caster, Unit target) {
        Log.Debug("run EarthQuake");
        Log.Debug("cfg", cfg.get(0).toString(), Integer.parseInt(cfg.get(1).toString()), cfg.get(2).toString());
    }

    static boolean CheckEarthQuake(ArrayList<Object> cfg) {
        Log.Debug("run CheckEarthQuake");
     return true;
    }

    //不同配置格式，试下类似功能：
    //例如： EarthQuakeEx 3 表示 3 级地震
    // EarthQuake1 3,2 表示地震级别= 3+ 角色等级*2 
    static void EarthQuake1(ArrayList<Object> cfg, Unit caster, Unit target) {
        ArrayList<Object> calCfg = new ArrayList<>();
        //calCfg[0]= cfg[0] +caster.lv * cfg[1] 
        EarthQuakeEx(calCfg, caster, target);
    }
    static void EarthQuakeEx(ArrayList<Object> cfg, Unit caster, Unit target) {
        
    }
  
    static void C1(ArrayList<Object> cfg, Unit caster, Unit target) {
        Log.Debug("run C1");
        Log.Debug("cfg", cfg.get(0).toString(), Integer.parseInt(cfg.get(1).toString()), cfg.get(2).toString());
    }
    static boolean CheckC1(ArrayList<Object> cfg) {
        if (cfg.size()!=3) {
            Log.Error("invalid cfg for C1");
            return false;
        }
     return true;
    }

    //例如配置内容：  ”Part“, "EarthQuake", 1, ”Part“, "c1", 2
    //组合执行2个效果: EarthQuake, C1
    static void Part(ArrayList<Object> cfg, Unit caster, Unit target) {
        if (cfg == null || cfg.isEmpty()) {
            Log.Error("Invalid cfg for Part");
            return;
        }

        ArrayList<Object> currentGroup = null;
        
        for (Object item : cfg) {
            // 处理非Part的情况
            if (!"Part".equals(item.toString())) {
                if (currentGroup != null) {
                    currentGroup.add(item);
                }
                continue;
            }

            // 处理Part分隔符
            if (currentGroup != null && currentGroup.size() >= 1) {
                EffectMgr.DoEffect(currentGroup, caster, target);
            }
            currentGroup = new ArrayList<>();
        }
        
        // 执行最后一组
        if (currentGroup != null && currentGroup.size() >= 1) {
            EffectMgr.DoEffect(currentGroup, caster, target);
        }
    }

   static boolean CheckPart(ArrayList<Object> cfg) {
        if (cfg == null || cfg.isEmpty()) {
            Log.Error("Invalid cfg for Part");
            return false;
        }

        ArrayList<Object> currentGroup = null;
        boolean allValid = true;
        
        for (Object item : cfg) {
            // 处理非Part的情况
            if (!"Part".equals(item.toString())) {
                if (currentGroup != null) {
                    currentGroup.add(item);
                }
                continue;
            }

            // 处理Part分隔符
            if (currentGroup != null && currentGroup.size() >= 1) {
                if (!EffectMgr.CheckCfg(currentGroup)) {
                    allValid = false;
                }
            }
            currentGroup = new ArrayList<>();
        }
        
        // 检查最后一组
        if (currentGroup != null && currentGroup.size() >= 1) {
            if (!EffectMgr.CheckCfg(currentGroup)) {
                allValid = false;
            }
        }
        
        return allValid;
    }
}
